$.ajax({
    type: 'get',
    url: '/comments',
    success: function(response) {
        var html = template('commentsTpl', response);
        var pageHTML = template('pageTpl', response)
        $('#commentsBox').html(html)
        $('#pageBox').html(pageHTML)
    }
});
//修改评论状态
$('#commentsBox').on('click', '.status', function() {
    var id = $(this).data('id');
    var status = $(this).data('status')
    $.ajax({
        type: 'put',
        url: '/comments/' + id,
        data: {
            state: status == 0 ? 1 : 0
        },
        success: function() {
            location.reload();
        }
    })
});
//删除评论
$('#commentsBox').on('click', '.delete', function() {
    if (confirm('是否删除次评论')) {
        var id = $(this).data('id');
        $.ajax({
            type: 'delete',
            url: '/comments/' + id,
            success: function() {
                location.reload();
            }
        })
    }
});